package com.loveazure.bll.algorithm;

import java.util.Set;

import com.loveazure.bll.Handler;
import com.loveazure.eo.Cent;
import com.loveazure.eo.WordLearned;

public class WordItem {

	/* 对单词的熟悉速度的估量值 */
	private double EF;

	private int index;

	/* 单词发音文件的位置 */
	private String pronouncePath;

	private WordLearned wordLearned;

	public WordItem(WordLearned wordLearned) {
		this.wordLearned = wordLearned;
		this.pronouncePath = "pron/" + getName().substring(0, 1).toUpperCase()
				+ "/" + getName() + ".mp3";

		// SM2:With all items associate an E-Factor equal to 2.5.
		this.EF = 2.5;
	}

	public String getDefinition() {
		return wordLearned.getDict().getDef();
	}

	public double getEF() {
		return EF;
	}

	public int getIndex() {
		return index;
	}

	public String getName() {
		return wordLearned.getDict().getName();
	}

	public String getPronouncePath() {
		return pronouncePath;
	}

	public String getPsymbol() {
		return wordLearned.getDict().getPron();
	}

	public int getQuality() {
		return wordLearned.getQuality();
	}

	public int getTimes() {
		return wordLearned.getTimes();
	}

	public void setEF(double eF) {
		EF = eF;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public void setPronouncePath(String pronouncePath) {
		this.pronouncePath = pronouncePath;
	}

	public void setQuality(int quality) {
		wordLearned.setQuality(quality);
	}

	public void setTimes(int times) {
		wordLearned.setTimes(times);
	}

	public void updateLearnedWord() {
		Handler.getInstance().getOper().updateLearnedWord(this.wordLearned);
	}

	public String getCent() {
		Set<Cent> set = wordLearned.getDict().getCent();
		if (set == null || set.size() == 0) {
			return "";
		}
		StringBuffer sb = new StringBuffer();
		int i = 1;
		for (Cent c : set) {
			sb.append(i++).append(". ").append(c.getOrig())
					.append(c.getTrans()).append("\n");
		}
		return sb.toString();
	}
}
